package top.tangyh.lamp.care.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.ErrorResponse;
import org.springframework.web.bind.annotation.*;
import top.tangyh.basic.base.R;
import top.tangyh.basic.interfaces.echo.EchoService;
import top.tangyh.basic.base.controller.SuperController;
import top.tangyh.lamp.care.entity.BPipeObsvRecord;
import top.tangyh.lamp.care.service.BPipeObsvRecordService;
import top.tangyh.lamp.care.service.BPipeUseRecordService;
import top.tangyh.lamp.care.entity.BPipeUseRecord;
import top.tangyh.lamp.care.vo.query.*;
import top.tangyh.lamp.care.vo.result.BPipeObsvRecordResultVO;
import top.tangyh.lamp.care.vo.result.PageOutputDTO;
import top.tangyh.lamp.care.vo.result.PipeLatestObsvRecordDTO;
import top.tangyh.lamp.care.vo.save.BPipeUseRecordSaveVO;
import top.tangyh.lamp.care.vo.update.BPipeUseRecordUpdateVO;
import top.tangyh.lamp.care.vo.result.BPipeUseRecordResultVO;
import top.tangyh.lamp.care.vo.update.ChangeYxPipeUseRecordParam;

import javax.validation.Valid;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * 导管使用记录具体信息表
 * </p>
 *
 * @author zqb
 * @date 2024-07-19 15:02:24
 * @create [2024-07-19 15:02:24] [zqb] [代码生成器生成]
 */
@Slf4j
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/channel")
@Tag(name = "系统：管道管理")
public class BPipeUseRecordController {

//    extends SuperController<BPipeUseRecordService, Long, BPipeUseRecord
//            , BPipeUseRecordSaveVO, BPipeUseRecordUpdateVO, BPipeUseRecordPageQuery, BPipeUseRecordResultVO>
//    private final EchoService echoService;
//    @Override
//    public EchoService getEchoService() {
//        return echoService;
//    }

    private final BPipeUseRecordService bPipeUseRecordService;

    private final BPipeObsvRecordService bPipeObsvRecordService;


    @PostMapping("/select/allPipeUseRecord")
    @Operation(summary = "查询所有管道信息(护理记录模块需要调用)")
    public R<Map<String, Object>> selectAllPipeUseRecord(@RequestBody PipeUseRecordQueryVO queryAllCatheterInfoParam) {
        return R.success(bPipeUseRecordService.queryAllPipeUseRecord(queryAllCatheterInfoParam));
    }






    /**
     * 导管信息添加或修改 ---拔管
     */
    @PostMapping("/addOrUpdate/pipeUseRecord")
    @Operation(summary = "新增/修改管道信息/--拔管")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "0", description = "传值数据为空"
//                    content =
//                    { @Content(mediaType = "application/json", schema =
//                    @Schema(implementation = BPipeUseRecord.class)) }
            ),
            @ApiResponse(responseCode = ">0", description = "更新成功"),
            @ApiResponse(responseCode = "-1", description = "更新失败"),
//            @ApiResponse(responseCode = "400", description = "Invalid ID supplied"),
//            @ApiResponse(responseCode = "404", description = "Customer not found"),
//            @ApiResponse(responseCode = "500", description = "Internal server error", content =
//                    { @Content(mediaType = "application/json", schema =
//                    @Schema(implementation = ErrorResponse.class)) })
    })
    public R<Long> addOrUpdateYxPipeUseRecord(@RequestBody BPipeUseRecord pipeUseRecordPO) {

        //his对接后 需要增加保存 床位号和科室的逻辑 ...

        Long result = bPipeUseRecordService.addOrUpdateYxPipeUseRecord(pipeUseRecordPO);
        if (result == 0) {
            return R.fail("保存参数不能为空");
        } else if (result == -1) {
            return R.fail("报错失败");
        }
        return R.success(result);
    }


//    /**
//     只是为了在models里显示 PipeUseRecordVO
//     */
//    @PostMapping("/swagger2/test")
//    @Operation(summary ="只是为了在models里显示 PipeUseRecordVO")
//    public R<Object> test(@RequestBody PipeUseRecordVO pipeUseRecordVO) {
//        return R.success();
//    }

    /**
     * 换管更新
     */
    @PostMapping("/update/pipeUseRecord")
    @Operation(summary = "换管道更新")
    public R updateYxPipeUseRecord(@RequestBody ChangeYxPipeUseRecordParam changeYxPipeUseRecordParam) {
        if (null != changeYxPipeUseRecordParam.getId()) {
            if (bPipeUseRecordService.updateYxPipeUseRecord(changeYxPipeUseRecordParam)) {
                return R.success();
            } else {
                return R.fail("更新失败");
            }
        } else {
            return R.fail("需要提供修改管道的编号");
        }

    }

    /**
     * 删除导管信息
     */
    @GetMapping("/delete/pipeUseRecord/{id}")
    @Operation(summary = "删除管道信息")
    public R<Object> deleteYxPipeUseRecordById(@PathVariable(value = "id") Long id) {
        return R.success(bPipeUseRecordService.deleteYxPipeUseRecordById(id));
    }


//    /**
//     * 查询导管观察记录
//     */
//    @PostMapping("/page/pipeUserRecord")
//    @Operation(summary = "分页管道记录")
//    public R<PageOutputDTO<BPipeObsvRecordResultVO>> queryAllYxPipeObsvRecord(@RequestBody QueryPipeObsvRecorddParam queryYxPipeObsvRecorddParam) {
//        return R.success(bPipeObsvRecordService.queryPageOfPipeObsvRecord(queryYxPipeObsvRecorddParam));
//    }

    /**
     * 查询导管观察记录
     */
    @PostMapping("/query/page/allPipeObsvRecord")
    @Operation(summary = "分页查询管道观察记录（护理记录模块需要调用）")
    public R<PageOutputDTO<BPipeObsvRecordResultVO>> queryAllYxPipeObsvRecord(@RequestBody QueryPipeObsvRecorddParam queryYxPipeObsvRecorddParam) {
        return R.success(bPipeObsvRecordService.queryPageOfPipeObsvRecord(queryYxPipeObsvRecorddParam));
    }


    /**
     * 添加导管观察记录
     */
    @PostMapping("/addOrUpdate/pipeObsvRecord")
    @Operation(summary = "添加修改管道观察记录")
    public R<Object> addYxPipeObsvRecord(@RequestBody BPipeObsvRecord yxPipeObsvRecordPO) {
        return R.success(bPipeObsvRecordService.addOrUpdateYxPipeObsvRecord(yxPipeObsvRecordPO));
    }


    /**
     * 删除导管观察记录
     */
    @GetMapping("/delete/pipeObsvRecord/{id}")
    @Operation(summary = "删除管道观察记录")
    public R<Object> deleteYxPipeObsvRecord(@PathVariable(value = "id") Long id) {
        return R.success(bPipeObsvRecordService.deleteYxPipeObsvRecord(id));
    }


    /**
     * 获取上次同类型管道观察记录
     */
    @PostMapping("/pipeObsvRecord/latest")
    @Operation(summary = "删除管道观察记录")
    public R<PipeLatestObsvRecordDTO> getPipeObsvLatestRecord(@RequestBody @Valid PipeObsvRecorddLatestParam yxPipeObsvRecorddLatestParam) {
        return R.success(bPipeObsvRecordService.getPipeObsvLatestRecord(yxPipeObsvRecorddLatestParam));
    }

}


